function [vl_lwin2_lwon1,vh_lwin2_lwon1,vl_llose2_lwon1,vh_llose2_lwon1,vl_lwin2_llost1,vh_lwin2_llost1,vl_llose2_llost1,vh_llose2_llost1,p_lwin2_lwon1,p_llose2_lwon1,p_lwin2_llost1,p_llose2_llost1]=transition_prob_stage2(parameter,tpORtp3h,Cpm25,parameter_fixed,c_l,c_h,V_l,V_h)


N=size(c_l,1);

% Parameters that are fixed
delta_0   =parameter_fixed(1);

% Parameters that are estimated 
k        =parameter(1);
delta_tp =parameter(3);
delta_pm =parameter(4);
cutoff_tp=parameter(5);
cutoff_pm=parameter(6);           % Estimate environment cutoffs
                
% Delta changes separately in the log of (1 +) the temperature or PM2.5 difference relative to a cutoff, i.e., temperature of 27 -> log (1 + 27 - cutoff) = log (1 + 27 - 27) = log 1 = 0; 28->.7 of delta; 43->2.8   
delta = repmat(delta_0,N,1) + delta_tp * log( max( (tpORtp3h - repmat(cutoff_tp,N,1)) , 0) + ones(N,1)) + delta_pm * log( max( (Cpm25 - repmat(cutoff_pm,N,1)) , 0) + ones(N,1));


% Call on transition_prob_oneshot
[p_lwin3,p_llose3]=transition_prob_oneshot(c_l,c_h,V_l,V_h,k);

% Equilibrium effort costs incurred in stage 3: Equal across symmetric players (equal marginal cost and equal contest prizes) 
effortcostl_stage3=k*V_l.*( ((c_l./c_h).*(V_h./V_l)).^k ) ./ ( (ones(N,1)+((c_l./c_h).*(V_h./V_l)).^k).^2 );
effortcosth_stage3=k*V_h.*( ((c_h./c_l).*(V_l./V_h)).^k ) ./ ( (ones(N,1)+((c_h./c_l).*(V_l./V_h)).^k).^2 );

% Conditional on lwon1: Continuation values (in stage 3) conditional on stage-2 outcome (and stage-1 history)
vl_lwin2_lwon1 =V_l;                                        % For the two-setter here, player l earns the player-specific contest prize in stage 2 (no stage-3 utility flow)
vh_lwin2_lwon1 =zeros(N,1);
vl_llose2_lwon1=p_lwin3 .*V_l - effortcostl_stage3 - delta; % Each player's respective contest prize may be earned & effort cost & per-battle environmental disutility to be incurred in stage 3
vh_llose2_lwon1=p_llose3.*V_h - effortcosth_stage3 - delta;
spread_l=vl_lwin2_lwon1-vl_llose2_lwon1;                    % Player l's stage-2 win/lose payoff spread, conditional on lwon1
spread_h=vh_llose2_lwon1-vh_lwin2_lwon1;                    % Player h's stage-2 win/lose payoff spread, conditional on lwon1
% Equilibrium effort costs incurred in stage 2: Different across players given different win/lose payoffs spreads in stage 2
effortcostl_stage2=k*spread_l.*( ((c_l./c_h).*(spread_h./spread_l)).^k ) ./ ( (ones(N,1)+((c_l./c_h).*(spread_h./spread_l)).^k).^2 );
effortcosth_stage2=k*spread_h.*( ((c_h./c_l).*(spread_l./spread_h)).^k ) ./ ( (ones(N,1)+((c_h./c_l).*(spread_l./spread_h)).^k).^2 );
    % CORNER: If vh_llose2_lwon1<=0 <=> spread_h<=0, then battle-1 loser (player h in this case) throws the towel in battle 2: it is best to not exert effort, finish 2-0 and secure CV=0, than to try to transition to 1-1 with CV<0
    effortcostl_stage2=effortcostl_stage2.*(vh_llose2_lwon1>0);
    effortcosth_stage2=effortcosth_stage2.*(vh_llose2_lwon1>0);
    zero_spread_h=(spread_h==0);                 % Need to handle division by spread_h=0, which returned NaN
    effortcosth_stage2(zero_spread_h)=0;
% Divide a player's equilibrium effort cost by marginal cost to obtain effort choice; lambda=1
xl2_lwon1=effortcostl_stage2./c_l;
xh2_lwon1=effortcosth_stage2./c_h;
% Transition probabilities   
p_lwin2_lwon1 = xl2_lwon1.^k ./ (xl2_lwon1.^k + xh2_lwon1.^k);
% Can subsequently call on transition_prob_oneshot to speed up; as well as comment out the clear command?
%p_lwin2_lwon1=ones(N,1)./(ones(N,1)+(c_l./c_h.*spread_h./spread_l).^k);
%p_lwin2_lwon1=transition_prob_oneshot(c_l,c_h,spread_l,spread_h,k);
    % CORNER
    p_lwin2_lwon1(xl2_lwon1==0)=1;              % In battle 2, player l exerts infinitesimally positive effort and wins over player h who exerts 0 effort
p_llose2_lwon1=ones(N,1)-p_lwin2_lwon1;
clear spread_l spread_h effortcostl_stage2 effortcosth_stage2 zero_spread_h;
clear effortcost_stage3;

% Conditional on llost1: Continuation values (in stage 3) conditional on stage-2 outcome (and stage-1 history)
vl_lwin2_llost1 =vl_llose2_lwon1;                           
vh_lwin2_llost1 =vh_llose2_lwon1;			
vl_llose2_llost1=zeros(N,1);	
vh_llose2_llost1=V_h;                                       % For the two-setter here, player h earns the player-specific contest prize in stage 2 (no stage-3 utility flow)
spread_l=vl_lwin2_llost1-vl_llose2_llost1;                  % Player l's stage-2 win/lose payoff spread, conditional on llost1
spread_h=vh_llose2_llost1-vh_lwin2_llost1;                  % Player h's stage-2 win/lose payoff spread, conditional on llost1
% Equilibrium effort costs incurred in stage 2: Different across players given different win/lose payoffs spreads in stage 2
effortcostl_stage2=k*spread_l.*( ((c_l./c_h).*(spread_h./spread_l)).^k ) ./ ( (ones(N,1)+((c_l./c_h).*(spread_h./spread_l)).^k).^2 );
effortcosth_stage2=k*spread_h.*( ((c_h./c_l).*(spread_l./spread_h)).^k ) ./ ( (ones(N,1)+((c_h./c_l).*(spread_l./spread_h)).^k).^2 );
    % CORNER: If vl_lwin2_llost1<=0 <=> spread_l<=0, then battle-1 loser (player l in this case) throws the towel in battle 2: it is best to not exert effort, finish 0-2 and secure CV=0, than to try to transition to 1-1 with CV<0
    effortcostl_stage2=effortcostl_stage2.*(vl_lwin2_llost1>0);
    effortcosth_stage2=effortcosth_stage2.*(vl_lwin2_llost1>0);
    zero_spread_l=(spread_l==0);                 % Need to handle division by spread_l=0, which returned NaN 
    effortcostl_stage2(zero_spread_l)=0;
% Divide a player's equilibrium effort cost by marginal cost to obtain effort choice; lambda=1
xl2_llost1=effortcostl_stage2./c_l;
xh2_llost1=effortcosth_stage2./c_h;
% Transition probabilities
p_lwin2_llost1 = xl2_llost1.^k ./ (xl2_llost1.^k + xh2_llost1.^k);
% Can subsequently call on transition_prob_oneshot to speed up; as well as comment out the clear commands?
%p_lwin2_llost1=ones(N,1)./(ones(N,1)+(c_l./c_h.*spread_h./spread_l).^k);
%p_lwin2_llost1=transition_prob_oneshot(c_l,c_h,spread_l,spread_h,k);
    % CORNER
    p_lwin2_llost1(xl2_llost1==0)=0;              % In battle 2, player h exerts infinitesimally positive effort and wins over player l who exerts 0 effort
p_llose2_llost1=ones(N,1)-p_lwin2_llost1;
clear spread_l spread_h effortcostl_stage2 effortcosth_stage2 zero_spread_l;

end